        package DAL;

        import java.util.*;
        
        import DBUtil.SQLUtil;
        
        public class Player {

		//获取运动员信息列表
		public List<Object> getEntity()
		{
			String sqlCmd="select *from Player";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
		}
            
               //获取分页后运动员信息列表
		public List<Object> getEntity(int page)
		{
			int size=(page-1)*15;
			String sqlCmd="select *from V_Player limit "+size+",15";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
		}
                
               //根据查询条件sqlWhere获取分页后运动员信息列表
		public List<Object> getEntityByWhere(String sqlWhere,int page)
		{
			int size=(page-1)*15;
			String sqlCmd="select *from V_Player where "+sqlWhere+" limit "+ size+",15";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
        }
        
        //删除运动员信息
        public int deleteEntity(String PlayerId)
        {
            String sqlCmd="delete from Player where PlayerId='"+PlayerId+"'";
            return DBUtil.SQLUtil.executeNonQuery(sqlCmd, null);//执行非查询操作executeNonQuery
        }
        
        //根据运动员编号获取运动员信息
        public List<Object> getEntityById(String PlayerId)
        {
            String sqlCmd="select *From Player where PlayerId='"+PlayerId+"'";
            return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
        }
        
        //更新运动员信息
        public int updateEntity(String PlayerId,String PlayerName,String PlayerSex,String PId,String PlayerClass)
        {
            String sqlCmd="Update Player set PlayerName='" + PlayerName + "',PlayerSex='" + PlayerSex + "',PId='" + PId + "',PlayerClass='" + PlayerClass + "' where PlayerId='"+PlayerId+"'";
            return SQLUtil.executeNonQuery(sqlCmd, null);
        }
        
        //插入运动员信息
        public int insertEntity(String PlayerId,String PlayerName,String PlayerSex,String PId,String PlayerClass)
        {
            String sqlCmd="Insert into Player values('" + PlayerId + "','" + PlayerName + "','" + PlayerSex + "','" + PId + "','"+PlayerClass+"')";
            return SQLUtil.executeNonQuery(sqlCmd, null);
        }
        
        //检查插入主键是否重复
        public boolean checkExist(String PlayerId)
        {
            String sqlCmd="select count(*) from Player where PlayerId='"+PlayerId+"'";
            if(1==Integer.parseInt(SQLUtil.excuteScalar(sqlCmd, null).toString()) )
            {
                return true;
            }
            return false;
        }

		//获取分页总数
		public Object getPageCount()
		{
			String sqlCmd="SELECT CEIL( COUNT(*)/15.0) FROM V_Player ";
			return SQLUtil.excuteScalar(sqlCmd, null);
		}

		//根据查询条件获取分页总数
		public Object getPageCountByWhere(String sqlWhere)
		{
			String sqlCmd="SELECT CEIL( COUNT(*)/15.0) FROM V_Player where "+sqlWhere;
			return SQLUtil.excuteScalar(sqlCmd, null);
		}
            
 }
